#include "widget.h"
#include "ui_widget.h"

#include <QDebug>
#include <fstream>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    // 读取config.txt文件内容,作为combobox选项
    std::ifstream file("D:/Remote repositories/qt-code/QComboBox_2/config.txt");
    if(!file.is_open()) {
        qDebug() << "文件打开失败";
        return;
    }
    // 按行读取文本内容
    std::string line;
    while(std::getline(file, line)) {
        // 取到的每一行内容都设置到combobox下拉框中
        ui->comboBox->addItem(QString::fromStdString(line));
    }
    file.close();
}

Widget::~Widget()
{
    delete ui;
}
